package com.lee.auth.security;

import com.lee.auth.security.config.PathSecurity;
import com.lee.auth.security.config.PathSecurityConfigurer;
import com.lee.auth.security.context.AuthContextVerifier;
import org.springframework.context.annotation.Configuration;

/**
 * @author lee HN
 * @date 2021/4/6 19:28
 */
@Configuration
public class CustomPathSecurityConfigurer implements PathSecurityConfigurer {

    /**
     * 通过path匹配判断路径权限  Handler越靠前 优先级越高  匹配到以后不再继续匹配
     * 尽量将高频率访问路径配置在前 提高匹配效率
     * 全路径匹配不添加路径代替"/**"
     *
     * @param security
     */
    @Override
    public void configure(PathSecurity security) {
        security.addPathHandler((req, resp) -> AuthContextVerifier.permitAll(), "/login/**")
                .addPathHandler((req, resp) -> AuthContextVerifier.isAuthenticated());
    }

}
